Skip to content

Conversation

@BobbieGoede
Copy link
Contributor

@BobbieGoede BobbieGoede commented Feb 3, 2026

This is incomplete.

Only handles Ukrainian at the moment, and for some reason the warning inside the dev if statement is not being logged.

Falls back to the highest plural form if given plural amount is not translated, also logs a warning in dev mode if this happens.

This results in inaccurate plurals if translations are incomplete, but the alternative is an error page.

@BobbieGoede BobbieGoede marked this pull request as draft February 3, 2026 16:24
@vercel
Copy link

vercel bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs.npmx.dev Error Error Feb 3, 2026 8:15pm
npmx.dev Ready Ready Preview, Comment Feb 3, 2026 8:15pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
npmx-lunaria Ignored Ignored Feb 3, 2026 8:15pm

Request Review

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
config/i18n.ts 22.22% 4 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

// In case translation doesn't have all plural forms, use the last available form
if (plural > choicesLength - 1) {
if (import.meta.dev) {
console.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add // oxlint-disable-next-line no-console -- warn logging

Copy link
Contributor

@userquin userquin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I guess we should patch intlify here and send a PR to intlify since we don't have the "failing" key 🤔:

Image

@userquin
Copy link
Contributor

userquin commented Feb 3, 2026

Looks like we need to add a test...

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

This change refactors the internationalization configuration by introducing a shared internal helper function createPluralRule that centralises plural form index computation using Intl.PluralRules. Multiple locale-specific implementations (ar, hu-HU, ru-RU, uk-UA, cs-CZ, pl-PL) are replaced with calls to this helper function. The modification maintains existing behaviour for out-of-bounds form handling and development-time warnings. However, the diff indicates a duplicate function declaration exists within the same module.

Suggested reviewers

  • whitep4nth3r
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, describing fallback behaviour for missing plural translations and development-mode warnings.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
config/i18n.ts (1)

81-99: Cache Intl.PluralRules instance outside the returned closure.

Creating a new Intl.PluralRules instance on every pluralisation call is inefficient. Move the instantiation into the outer scope so it's created once per locale.

Additionally, consider using ?? instead of || on line 84 for clearer intent when handling undefined, and typing the mapping with Intl.LdmlPluralRule keys for stricter type safety.

♻️ Proposed refactor
-function createPluralRule(locale: string, mapping: Record<string, number>) {
+function createPluralRule(locale: string, mapping: Partial<Record<Intl.LdmlPluralRule, number>>) {
+  const pluralRules = new Intl.PluralRules(locale)
   return (choice: number, choicesLength: number) => {
-    const name = new Intl.PluralRules(locale).select(choice)
-    const plural = mapping[name] || 0
+    const name = pluralRules.select(choice)
+    const plural = mapping[name] ?? 0

     // In case translation doesn't have all plural forms, use the last available form
     if (plural > choicesLength - 1) {

const name = new Intl.PluralRules('pl-PL').select(choice)
return { zero: 0, one: 1, two: 0, few: 2, many: 3, other: 4 }[name]
},
pluralRule: createPluralRule('pl-PL', { zero: 0, one: 1, two: 0, few: 2, many: 3, other: 4 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cd /dev/shm/repo && find . -name "i18n.ts" -o -name "config" -type d | head -20

Repository: npmx-dev/npmx.dev

Length of output: 124


🏁 Script executed:

cd /dev/shm/repo && fd -t f "i18n" | head -20

Repository: npmx-dev/npmx.dev

Length of output: 124


🏁 Script executed:

cd /dev/shm/repo && cat -n config/i18n.ts | head -30

Repository: npmx-dev/npmx.dev

Length of output: 124


🏁 Script executed:

git ls-files | head -30

Repository: npmx-dev/npmx.dev

Length of output: 667


🏁 Script executed:

fd -t f "i18n.ts"

Repository: npmx-dev/npmx.dev

Length of output: 75


🏁 Script executed:

cat -n config/i18n.ts | sed -n '230,310p'

Repository: npmx-dev/npmx.dev

Length of output: 2197


🏁 Script executed:

cat -n config/i18n.ts | sed -n '1,100p'

Repository: npmx-dev/npmx.dev

Length of output: 4818


🏁 Script executed:

grep -n "createPluralRule" config/i18n.ts | head -20

Repository: npmx-dev/npmx.dev

Length of output: 758


🏁 Script executed:

node -e "console.log(new Intl.PluralRules('pl-PL').select(0))"

Repository: npmx-dev/npmx.dev

Length of output: 65


🏁 Script executed:

node -e "
const rule = new Intl.PluralRules('pl-PL');
console.log('choice 0:', rule.select(0));
console.log('choice 1:', rule.select(1));
console.log('choice 5:', rule.select(5));
console.log('choice 22:', rule.select(22));
"

Repository: npmx-dev/npmx.dev

Length of output: 119


Restore explicit zero handling for Polish locale or update plural form mapping.

The new implementation using createPluralRule introduces a behavioural regression. Intl.PluralRules('pl-PL').select(0) returns "many" (not "zero"), which maps to form index 3, whereas the previous implementation explicitly returned form index 0 for choice === 0. This changes how "0 items" is displayed in Polish.

Additionally, the zero: 0 key in the mapping is unreachable dead code—Intl.PluralRules('pl-PL') never returns a "zero" category for the Polish locale.

Either restore the explicit zero handling (as in the commented-out lines 241–247) within createPluralRule, or confirm this is intentional and update the mapping accordingly.

@danielroe danielroe added this pull request to the merge queue Feb 3, 2026
Merged via the queue into npmx-dev:main with commit c57d3b8 Feb 3, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants